package com.foreknow.elm.service.impl;

import com.foreknow.elm.dao.DeliveryAddressDao;
import com.foreknow.elm.dao.impl.DeliveryAddressDaoImpl;
import com.foreknow.elm.po.Deliveryaddress;
import com.foreknow.elm.service.DeliveryaddressService;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author shkstart
 * @create 2021-08-27 10:15
 */
public class DeliveryaddressServiceImpl implements DeliveryaddressService {
    /**
     * DeliveryAddressController/listDeliveryAddressByUserId
     *    参数：userId
     *    返回值：deliveryAddress数组
     *    功能：根据用户编号查询所属送货地址
     */
    @Override
    public List<Deliveryaddress> listDeliveryAddressByUserId(String userId) {
        List<Deliveryaddress> list=new ArrayList<>();
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        try {
            list = dao.listDeliveryAddressByUserId(userId);
            return list;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
    /**
     * DeliveryAddressController/getDeliveryAddressById
     *    参数：daId
     *    返回值：deliveryAddress对象
     *    功能：根据送货地址编号查询送货地址
     */
    @Override
    public Deliveryaddress getDeliveryAddressById(int daId) {
        Deliveryaddress das=new Deliveryaddress();
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        try {
            das = dao.getDeliveryAddressById(daId);
            return das;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return das;
    }
    /**
     *  DeliveryAddressController/saveDeliveryAddress
     *    参数：contactName、contactSex、contactTel、address、userId
     *    返回值：int（影响的行数）
     *    功能：向送货地址表中添加一条记录
     */
    @Override
    public int saveDeliveryAddress(String contactName, int contactSex, String contactTel, String address, String userId) {
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        try {
            int i = dao.saveDeliveryAddress(contactName, contactSex, contactTel, address, userId);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }
    /**
     *  DeliveryAddressController/updateDeliveryAddress
     *    参数：daId、contactName、contactSex、contactTel、address、userId
     *    返回值：int（影响的行数）
     *    功能：根据送货地址编号更新送货地址信息
     */
    @Override
    public int updateDeliveryAddress(int daId, String contactName, int contactSex, String contactTel, String address, String userId) {
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        try {
            int i = dao.updateDeliveryAddress(daId, contactName, contactSex, contactTel, address, userId);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return 0;
    }
    /**
     * DeliveryAddressController/removeDeliveryAddress
     *    参数：daId
     *    返回值：int（影响的行数）
     *    功能：根据送货地址编号删除一条记录
     */
    @Override
    public int removeDeliveryAddress(int daId) {
        DeliveryAddressDao dao=new DeliveryAddressDaoImpl();
        try {
            int i = dao.removeDeliveryAddress(daId);
            return i;
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return 0;
    }
}
